local filelog = require "filelog"

require "zrlhdenum"

-------------------------

local CardTool = { }

local CardColor = {
	diamonds = 1,	--方块
	clubs = 2,		--梅花
	hearts = 3,		--红桃
	spades = 4,		--黑桃
}

-----------------------------------

--转换牌数据
function CardTool.convert_card(carditem)
	if not carditem or not carditem.suit then
		return
	end
	
	local ct = CardColor[carditem.suit]
	local cv = tonumber(carditem.point) or 0
	if not ct or cv == 0 then
		return
	end
	local card = ct * 100 + cv
	
	return card
end

--转换牌数据
function CardTool.convert_cards(gameResult)
	local dragoncard = CardTool.convert_card(gameResult.dragonCard)
	local tigercard = CardTool.convert_card(gameResult.tigerCard)
	
	local allcards = {
		banker_cards = {dragoncard},
		player_cards = {tigercard},
	}
	
	return allcards
end

--获得开牌结果
function CardTool.get_opencardresult(gameResult)
	local is_fillcard = false
	
	--转换牌数据
	local allcards = CardTool.convert_cards(gameResult)
	
	local result_list = {
		banker_cards = allcards.banker_cards,
		player_cards = allcards.player_cards,
	}
	
	return result_list
end

--获得游戏结果
function CardTool.get_gameresult(gameResult)
	local prize_id = nil
	
	local banker_points = tonumber(gameResult.dragonPoint)
	local player_points = tonumber(gameResult.tigerPoint)
	if banker_points > player_points then
		prize_id = ELHDBetBtnId.BET_BTN_ID_BANKER
	elseif banker_points < player_points then
		prize_id = ELHDBetBtnId.BET_BTN_ID_PLAYER
	else
		prize_id = ELHDBetBtnId.BET_BTN_ID_TIE
	end
	
	--转换牌数据
	local allcards = CardTool.convert_cards(gameResult)
	
	local result_list = {
		banker_cards = allcards.banker_cards,
		player_cards = allcards.player_cards,
		banker_points = banker_points,
		player_points = player_points,
		prize_id = prize_id,
		ext_prize_list = {},
	}
	
	return result_list
end

return CardTool
